<template>
  <div class="app-container">
    <h4>故障派发</h4>
    <!-- 输入表单 -->
    <el-form label-width="120px">
      <el-form-item label="处理人">
        <el-select v-model="cpHitchFlat.person">
          <el-option value="李师傅" :label="'李师傅'" />
          <el-option value="黄师傅" :label="'黄师傅'" />
          <el-option value="韩师傅" :label="'韩师傅'" />
        </el-select>
      </el-form-item>
      <el-form-item label="预计完成时间">
        <el-date-picker
          v-model="cpHitchFlat.estimate"
          type="datetime"
          placeholder="选择日期时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="任务内容" style="width: 600px">
        <el-input
          type="textarea"
          autosize
          v-model="cpHitchFlat.assContent"
        ></el-input>
      </el-form-item>

      <el-form-item>
        <router-link
          :to="'/charging-pile/hitch_manager'"
          style="margin-right: 5px"
        >
          <el-button type="default" style="margin-right: 70px">返回</el-button>
        </router-link>
        <el-button
          :disabled="saveBtnDisabled"
          type="primary"
          @click="saveOrUpdate()"
        >
          保存
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
//引入api模块
import listApi from '@/api/charging-pile/hitch_manage'
export default {
  data() {
    return {
      saveBtnDisabled: false, //是否禁用保存按钮，防止表单重复提交
      //派发表
      cpHitchFlat: {
        hitchId: null,
        person: null,
      },
      //故障表
      cpHitch: {
        id: null,
      },
    }
  },
  created() {
    this.findCpHitchManagerById()
  },
  methods: {
    //派发
    saveOrUpdate() {
      //禁用保存按钮
      this.saveBtnDisabled = true
      //调用派发
      this.saveData()
    },
    //派发
    saveData() {
      //派发
      ;(this.cpHitch.id = this.cpHitchFlat.hitchId),
        listApi.updateCpHitchStatusOne(this.cpHitch).then((res) => {})
      listApi
        .addCpHitchFlat(this.cpHitchFlat, this.$route.params.id)
        .then((response) => {
          console.log('(this.cpHitchFlat)=========' + this.cpHitchFlat)
          this.$message.success(response.message)
          this.$router.push('/charging-pile/hitch_manager') //路由地址进行改变
        })
    },
    //获取id
    findCpHitchManagerById() {
      listApi.findCpHitchManagerById(this.$route.params.id).then((res) => {
        console.log(this.$route.params.id)
        this.cpHitchFlat.hitchId = this.$route.params.id
      })
    },
  },
}
</script>
